<template>
  <!-- 小日历 -->
  <view class="little-calendar">
    <view class="title">出行日期</view>
    <view v-if="littleCalendar" class="calendar-list">
      <view
        v-for="(item,index) in weekDayList"
        :key="index"
        :class="{'calendar-list-item':true, 'not-open':!item.ticketBeing&&index!==weekDayList.length-1,active:index===Indexes}"
        @click="changeDate(index,item)"
      >
        <!-- :class="item.ticketBeing?'calendar-list-item active':'calendar-list-item not-open'" -->
        <!-- 上半部分 -->
        <view
          v-if="index===0 || index===1"
          class="calendar-list-item-top"
        >{{ index===0 ? '今天' : index === 1 ? '明天':'' }}</view>
        <view
          v-if="index!==7"
          class="calendar-list-item-content"
          :style="index===0 || index===1 ? 'height:100rpx':'height:140rpx'"
        >
          <view
            class="date"
            :style="index===0 || index===1 ?'margin-top:12rpx':'margin-top:30rpx'"
          >{{ item.date }}</view>
          <view
            class="price"
            style="margin-top:6rpx; font-weight: 400;font-size: 24rpx;"
          >{{ item.ticketBeing?'¥'+price:'暂未开放' }}</view>
        </view>
        <view v-else class="calendar-list-item-content" style="height:140rpx;">
          <view
            style="font-size:28rpx;width:56rpx;margin-left:42rpx;margin-top:30rpx;font-weight: 400;"
          >更多日期</view>
        </view>
      </view>
    </view>
    <view v-else class="calendar-view">
      <view class="left">
        <text style="font-weight:800;">{{ determineDate }}</text>
        <text>￥{{ price }}</text>
      </view>
      <view class="right" @click="showLargeCalendar">更改日期</view>
    </view>
    <!-- 大日历 -->
    <largeCalendar
      :date-list="dateList"
      :show="show"
      :price="price"
      :datetime="datetime"
      @close="close"
      @changeDate="changeDateBig"
    />
  </view>
</template>
<script>
import { showToast } from '@utils/myApproach'
import largeCalendar from '@com/order/largeCalendar'
export default {
  components: {
    largeCalendar
  },
  props: {
    weekDayList: {
      type: Array,
      default: null
    },
    price: {
      type: String,
      default: null
    },
    show: {
      type: Boolean,
      required: false
    },
    datetime: {
      type: String,
      default: null
    },
    dateList: {
      type: Array,
      default: null
    }
  },
  data() {
    return {
      Indexes: -1,
      littleCalendar: true,
      determineDate: null
    }
  },
  created() {
    // this.WeekDayList = this.getWeekDay()
    setTimeout(() => {}, 1000)
  },
  methods: {
    changeDate(index, item) {
      if (index === 7) {
        this.$emit('eject')
      } else {
        if (item.ticketBeing) {
          this.Indexes = index
          this.$emit('changeDatetime', item)
        } else {
          showToast('暂未开放,请选择其它日期')
        }
      }
    },
    changeDateBig(date) {
      this.littleCalendar = false
      console.log(date)
      this.determineDate = date.slice(5, 7) + '/' + date.slice(8, 10)
      this.$emit('changeDateBig', date)
    },
    close() {
      this.$emit('close')
    },
    showLargeCalendar() {
      this.$emit('eject')
    }
  }
}
</script>
<style lang="scss" scoped>
.little-calendar {
  width: 710rpx;
  background: #ffffff;
  box-shadow: 0rpx 0rpx 20rpx 0rpx rgba(0, 0, 0, 0.1);
  border-radius: 8rpx;
  margin-left: 20rpx;
  margin-bottom: 30rpx;
  padding-top: 30rpx;
  padding-bottom: 40rpx;
  .title {
    font-size: 32rpx;
    font-weight: 800;
    margin-left: 30rpx;
  }
  .calendar-list {
    display: flex;
    justify-content: start;
    flex-wrap: wrap;
  }
  .calendar-list-item {
    width: 136rpx;
    min-height: 136rpx;
    margin-left: 30rpx;
    background: #ffffff;
    box-shadow: 0px 0rpx 12rpx 0px rgba(215, 215, 215, 0.5);
    border-radius: 8rpx;
    margin-top: 30rpx;
    overflow-x: hidden;
    border: 2rpx solid;
    border-color: #ffffff;
  }
  .calendar-list-item-content {
    display: flex;
    flex-direction: column;
    justify-content: start;
    text-align: center;
    font-weight: 800;
    font-size: 28rpx;
  }
}
.calendar-list-item {
  .calendar-list-item-top {
    height: 40rpx;
    width: 136rpx;
    background-color: #306de9;
    border-radius: 8rpx 8rpx 0 0;
    color: #ffffff;
    font-size: 24rpx;
    text-align: center;
    line-height: 40rpx;
  }
}
.not-open {
  background-color: #b9b9b9 !important;
  color: #9b9b9b !important;
  border-color: #b9b9b9;
}
.active {
  border-color: #306de9 !important;
  background-color: #eaf0fc !important;
  .calendar-list-item-content {
    .date {
      color: #306de9 !important;
    }
    .price {
      color: #306de9 !important;
    }
  }
}
.calendar-view {
  display: flex;
  justify-content: space-between;
  margin-top: 30rpx;
  .left {
    width: 306rpx;
    border: 2rpx solid #306de9;
    background-color: #eaf0fc;
    height: 60rpx;
    border-radius: 8rpx;
    display: flex;
    justify-content: space-around;
    line-height: 60rpx;
    margin-left: 30rpx;
    text {
      font-size: 28rpx;
      color: #306de9;
    }
  }
  .right {
    font-size: 28rpx;
    color: #306de9;
    margin-right: 30rpx;
  }
}
</style>
